package com.homework;


import org.dom4j.Attribute;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.io.File;
import java.util.List;

/**
 * @author 于振晗
 * @title: HomeWork01
 * @description: TODO 编码题
 * @date 2020年09月08日
 * @path com.homework
 */
public class HomeWork01 {
    public static void main(String[] args) throws DocumentException {
        SAXReader saxReader = new SAXReader();
        Document read = saxReader.read(new File("Java_Xml/homework/clazs.xml"));
        Element rootElement = read.getRootElement();
        List<Element> elements = rootElement.elements();
        for (Element element : elements) {
            Attribute id = element.attribute("id");
            if(id!=null){
                System.out.println(id.getName() + "--->" + id.getValue());
            }
            List<Element> elements1 = element.elements();
            for (Element element1 : elements1) {
                System.out.println("\t"+element1.getName() + "--->" + element1.getText());
            }
        }
    }
}
